//
//  EnvironmentViewController.swift
//  BusinessIOS
//
//  Created by Rain on 2018/11/12.
//  Copyright © 2018 XingJian Li. All rights reserved.
//

import UIKit
import Alamofire
import PagingMenuController



//分页菜单配置
private struct PagingMenuOptions: PagingMenuControllerCustomizable {
    //第1个子视图曲靖概况
    private let viewController1 = ListViewController()
    
    
    //第2个子视图控制器曲靖优势
    private let viewController2 = NextListViewController()
    
    //    ThirdListViewController
    
    //第3个子视图控制器曲靖优势
    private let viewController3 = ThirdListViewController()
    
    //第4个子视图曲靖概况
    private let viewController4 = PingtaiViewController()
    
    
    //第5个子视图控制器曲靖优势
    private let viewController5 = ZhengCeViewController()

    
    //第6个子视图控制器曲靖优势
    private let viewController6 = BiaoShiViewController()
    

    
    //组件类型
    fileprivate var componentType: ComponentType {
        return .all(menuOptions: MenuOptions(), pagingControllers: pagingControllers)
    }
    
    //所有子视图控制器
    fileprivate var pagingControllers: [UIViewController] {
        return [viewController1, viewController2,viewController3,viewController4,viewController5,viewController6]
    }
    
    //菜单配置项

    
    fileprivate struct MenuOptions: MenuViewCustomizable {
        //菜单显示模式
        var displayMode: MenuDisplayMode {
            return .standard(widthMode:.flexible, centerItem: false, scrollingMode:.pagingEnabled)

        }
        
        
        //菜单项
        var itemsOptions: [MenuItemViewCustomizable] {
            return [MenuItem1(), MenuItem2(),MenuItem3(),MenuItem4(),MenuItem5(),MenuItem6()]
        }
    }
    
    //第1个菜单项
    fileprivate struct MenuItem1: MenuItemViewCustomizable {
        //自定义菜单项名称
        var displayMode: MenuItemDisplayMode {
            return .text(title: MenuItemText(text: "曲靖概况"))
        }
    }
    
    //第2个菜单项
    fileprivate struct MenuItem2: MenuItemViewCustomizable {
        //自定义菜单项名称
        var displayMode: MenuItemDisplayMode {
            return .text(title: MenuItemText(text: "曲靖优势"))
        }
    }
    
    //第3个菜单项
    fileprivate struct MenuItem3: MenuItemViewCustomizable {
        //自定义菜单项名称
        var displayMode: MenuItemDisplayMode {
            return .text(title: MenuItemText(text: "重点产业"))
        }
    }
    //第4个菜单项
    fileprivate struct MenuItem4: MenuItemViewCustomizable {
        //自定义菜单项名称
        var displayMode: MenuItemDisplayMode {
            return .text(title: MenuItemText(text: "投资平台"))
        }
    }
    //第5个菜单项
    fileprivate struct MenuItem5: MenuItemViewCustomizable {
        //自定义菜单项名称
        var displayMode: MenuItemDisplayMode {
            return .text(title: MenuItemText(text: "投资政策"))
        }
    }
    //第6个菜单项
    fileprivate struct MenuItem6: MenuItemViewCustomizable {
        //自定义菜单项名称
        var displayMode: MenuItemDisplayMode {
            return .text(title: MenuItemText(text: "企业标识"))
        }
    }
}



class EnvironmentViewController: UIViewController {

    var  numstring:String!
    
    var  newsClassName:String!
    var EnvironmentArray = [String]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = "投资环境"
        
          self.loadData()
        
        //分页菜单配置
        let options = PagingMenuOptions()
        //分页菜单控制器初始化
        let pagingMenuController = PagingMenuController(options: options)
        //分页菜单控制器尺寸设置
        pagingMenuController.view.frame.origin.y += 64
        pagingMenuController.view.frame.size.height -= 64
        
        //建立父子关系
        addChildViewController(pagingMenuController)
        //分页菜单控制器视图添加到当前视图中
        view.addSubview(pagingMenuController.view)
      

      
      
       
        
    }
    func loadData(){
        
         print("numstring====\(numstring!)")
        
        let urlString = "http://wwwqjzsyzcscom.aykj.net.cn/api/article/getChildNewsClass"
        let json = "{\"newsClassId\":\"\(numstring!)\"}"
        
        let url = URL(string: urlString)!
        let jsonData = json.data(using: .utf8, allowLossyConversion: false)!
        
        
        var request = URLRequest(url: url)
        request.httpMethod = HTTPMethod.post.rawValue
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        request.httpBody = jsonData
        
        Alamofire.request(request).responseJSON {
            (response) in
            print("====\(response)")
            if response.result.isSuccess {
                let json = JSON(response.data!)
                let array = json["resultData"].array
                
                for dataDic in  array! {
                    
//                    let model =   EnvironmentVModel()
                    
//
//                    model.newsClassId = dataDic["newsClassId"].string
                  
//                    model.newsClassName = dataDic["newsClassName"].string
                    self.newsClassName  = dataDic["newsClassName"].string
                    
                    self.EnvironmentArray.append(self.newsClassName!)
     
                    
                }
             
            } else {
                
            }
            
        }
        
        
    }
    
   
}
